/**
 * @param {number[]} A
 * @param {number[]} B
 * @return {number}
 */

var findLength = function(A, B) {
    var max=0
    if(A.length==0) {return max}
    size = A.length
    var ll= 0 ,rr=ll+1;
    var X = A.slice(ll,rr)
    while(X.length<=size || X.length<0)
    {
        var a = X.toString()
        var b = B.toString()
        a = ","+a+","
        b = ","+b+","
        if(-1!=b.indexOf(a)){
            var t = true
            X.forEach(element => {
                t = t && B.includes(element)
            });
            if(t) {
                max = max>X.length?max:X.length
                if(rr<size){rr++}else{
                    break;
                }
            }
            else{
                ll++
                if(rr==ll && rr<size)(rr++)
            }
        }
        else{
            ll++
            if(rr==ll && rr<size)(rr++)
        }
        if(ll==rr){
            break
        }
        X = A.slice(ll,rr)
    }
    return max
};
//r = findLength([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0])
//r = findLength([27,26,13,98,73,14,35,45,11,72,6,31,55,80,87,24,81,75,53,22,46,9,22,85,60,87,56,35,12,49,80,33,30,56,29,77,28,99,52,37,82,20,43,62,32,2,3,54,58,10,92,70,5,68,82,86,95,6,73,92,97,7,34,5,78,57,10,70,78,92,81,94,72,62,3,94,57,29,26,48,88,74,76,75,20,94,38,87,22,12,3,12,13,58,62,43,43,74,66,99],[50,88,0,77,54,73,76,53,17,5,25,42,42,95,31,32,10,54,94,2,65,38,86,70,98,31,27,84,77,78,41,4,81,32,82,92,22,49,6,21,32,8,80,67,12,27,41,16,62,12,45,27,34,39,54,37,24,90,73,54,48,85,3,67,42,52,97,18,69,26,22,80,39,11,47,60,9,58,53,9,91,7,0,29,43,55,55,43,21,13,97,4,98,60,21,78,74,15,23,74])
r = findLength([1,2,3,2,1],[3,2,1,4,7])
console.log(r)